<template>
    <div class="page-100 inspection-report-layout">
        <yd-tab horizontal-scroll
                v-model="tab"
                :callback="fn"
                :prevent-default="false"
                :item-click="itemClick"
                active-color="#3cc8a8">
            <yd-tab-panel v-for="item in level_one" :label="item.item_name">
                <div v-if="item.item_uuid==='YCHZ'">
                    <yd-cell-item v-for="bean in exceptionList">
                        <p slot="left">{{bean.name}}</p>
                        <p v-if="bean.result==='1'" slot="right">{{bean.good_text}}</p>
                        <p v-else-if="bean.result==='2'" slot="right" class="blue-color">{{bean.bad_text}}</p>
                    </yd-cell-item>
                </div>
                <div v-else-if="item.item_uuid==='YJYJY'" class="inspection-suggestion-layout">
                    <p class="inspection-suggestion-part">{{suggestion}}</p>
                    <!--图片显示组件-->
                    <!--:isSliderScroll="true"-->
                    <ImageShowComponent
                            :isSliderScroll="true"
                            class="inspection-img-part"
                            :imageList="images"/>
                </div>
                <div v-else>
                    <yd-cell-item v-for="bean in reportList">
                        <p slot="left">{{bean.name}}</p>
                        <p v-if="bean.result==='1'" slot="right">{{bean.good_text}}</p>
                        <p v-else-if="bean.result==='2'" slot="right" class="blue-color">{{bean.bad_text}}</p>
                    </yd-cell-item>
                </div>
            </yd-tab-panel>
        </yd-tab>
    </div>
</template>

<script>
    import {getExceptionReport,getReportSummary,getSubReport} from "../../pcof/post";
    import {inspectionType,userInfoData,qn_domain} from '../../globalVariables'
    import ImageShowComponent from "@/components/ImageShowComponent.vue";
    export default {
        name: "inspectionReportPage",
        data() {
            return {
                tab: 0,
                taskUUid: '',
                level_one: [],
                exceptionList: [],
                reportList: [],
                suggestion: '',
                images: [],
            }
        },
        components: {
            ImageShowComponent,
        },
        async created(){
            //接受上个页面传值 在实例创建完成后被立即调用
            this.taskUUid = this.$route.params.taskUUid;
            var index = this.$route.params.index;
            console.log(this.taskUUid);
            console.log(index);
            if (index === null || index === '') {
                index = 0;
            }
            this.tab = parseInt(index);
            this.level_one = JSON.parse(localStorage.getItem(inspectionType));

            if (this.level_one[index].item_uuid === "YCHZ") {
                var exceptionResponse = await getExceptionReport(JSON.parse(localStorage.getItem(userInfoData)).mobile,this.taskUUid);
                this.exceptionList = [];
                this.exceptionList = exceptionResponse.data.data.list;
            } else if (this.level_one[index].item_uuid === "YJYJY") {
                var summaryResponse = await getReportSummary(JSON.parse(localStorage.getItem(userInfoData)).mobile,this.taskUUid);
                if (summaryResponse.data.data.suggestion === "") {
                    this.suggestion = "无内容";
                } else {
                    this.suggestion = summaryResponse.data.data.suggestion;
                }
                if (summaryResponse.data.data.images === null || summaryResponse.data.data.images === '' || summaryResponse.data.data.images === undefined) {
                    this.images = [];
                } else {
                    var imgList = summaryResponse.data.data.images.split(",");
                    var list = [];
                    for (var i = 0;i<imgList.length;i++) {
                        list.push(localStorage.getItem(qn_domain)+imgList[i]);
                    }
                    this.images = list;
                }
            } else {
                var subReportResponse = await getSubReport(JSON.parse(localStorage.getItem(userInfoData)).mobile,this.taskUUid,this.level_one[index].item_uuid);
                console.log(subReportResponse);
                this.reportList = [];
                this.reportList = subReportResponse.data.data.list;
            }
        },
        methods: {
            fn(label, key) {
                console.log(label, key);
            },
            async itemClick(key) {
                this.$dialog.loading.open('数据加载中');
                if (this.level_one[key].item_uuid === "YCHZ") {
                    var exceptionResponse = await getExceptionReport(JSON.parse(localStorage.getItem(userInfoData)).mobile,this.taskUUid)
                    if (exceptionResponse.data.code === 200) {
                        this.$dialog.loading.close();
                        this.tab = key;
                        this.exceptionList = [];
                        this.exceptionList = exceptionResponse.data.data.list;
                    } else {
                        this.$dialog.loading.close();
                        this.tab = key;
                        this.$dialog.toast({
                            mes: exceptionResponse.data.msg,
                            timeout: 1500
                        });
                    }
                } else if (this.level_one[key].item_uuid === "YJYJY") {
                    var summaryResponse = await getReportSummary(JSON.parse(localStorage.getItem(userInfoData)).mobile,this.taskUUid);
                    if (summaryResponse.data.code === 200) {
                        this.$dialog.loading.close();
                        this.tab = key;
                        if (summaryResponse.data.data.suggestion === "") {
                            this.suggestion = "无内容";
                        } else {
                            this.suggestion = summaryResponse.data.data.suggestion;
                        }
                        if (summaryResponse.data.data.images === null || summaryResponse.data.data.images === '' || summaryResponse.data.data.images === undefined) {
                            this.images = [];
                        } else {
                            var imgList = summaryResponse.data.data.images.split(",");
                            var list = [];
                            for (var i = 0;i<imgList.length;i++) {
                                list.push(localStorage.getItem(qn_domain)+imgList[i]);
                            }
                            this.images = list;
                        }
                    } else {
                        this.$dialog.loading.close();
                        this.tab = key;
                        this.$dialog.toast({
                            mes: summaryResponse.data.msg,
                            timeout: 1500
                        });
                    }
                } else {
                    var subReportResponse = await getSubReport(JSON.parse(localStorage.getItem(userInfoData)).mobile,this.taskUUid,this.level_one[key].item_uuid);
                    if (subReportResponse.data.code === 200) {
                        this.$dialog.loading.close();
                        this.tab = key;
                        this.reportList = [];
                        this.reportList = subReportResponse.data.data.list;
                    } else {
                        this.$dialog.loading.close();
                        this.tab = key;
                        this.$dialog.toast({
                            mes: summaryResponse.data.msg,
                            timeout: 1500
                        });
                    }
                }
            }
        },
    }
</script>

<style lang="scss">
    @import "../login/login.scss";
    .inspection-report-layout {

        .inspection-suggestion-layout {
            padding: 0.2rem;

            .inspection-suggestion-part {
                text-align: left;
                padding: 0.6rem;
                border: 1px solid #e6e6e6;
            }

            .inspection-img-part {
                padding-left: 0.4rem;
            }
        }
    }
</style>